<template>
  <el-card>
    <el-form inline="true">
      <el-form-item label="1级">
        <el-select
          :disabled="scene == 0 ? false : true"
          v-model="categoryStore.c1Id"
          @change="handler"
        >
          <!-- label:展示的数据   value：select下拉菜单收集的数据 -->
          <el-option
            v-for="c1 in categoryStore.c1Arr"
            :key="c1.id"
            :label="c1.name"
            :value="c1.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="2级">
        <el-select
          :disabled="scene == 0 ? false : true"
          v-model="categoryStore.c2Id"
          @change="handler2"
        >
          <el-option
            v-for="c2 in categoryStore.c2Arr"
            :key="c2.id"
            :label="c2.name"
            :value="c2.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="3级">
        <el-select
          :disabled="scene == 0 ? false : true"
          v-model="categoryStore.c3Id"
        >
          <el-option
            v-for="c3 in categoryStore.c3Arr"
            :key="c3.id"
            :label="c3.name"
            :value="c3.id"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script setup lang="ts">
//引入组件挂载完毕方法
import { onMounted } from 'vue'
import useCategoryStore from '@/store/modules/category'
let categoryStore = useCategoryStore()
//分类全局组件挂载完毕，通知仓库发请求获取1级分类的数据
onMounted(() => {
  getC1()
})
//通知仓库获取1级分类的方法
const getC1 = () => {
  //通知分类仓库发请求获取1级分类的数据
  categoryStore.getC1()
}

//1级菜单下拉菜单的change事件（选中值时触发）
const handler = () => {
  //需要将23级分类数据清空
  ;(categoryStore.c2Id = ''),
    (categoryStore.c3Id = ''),
    (categoryStore.c3Arr = []),
    //通知仓库获取2级分类的数据
    categoryStore.getC2()
}
//2级菜单下拉菜单的change事件（选中值时触发）
const handler2 = () => {
  ;(categoryStore.c3Id = ''),
    //通知仓库获取3级分类的数据
    categoryStore.getC3()
}

//接收父组件传递的scene
defineProps(['scene'])
</script>

<style scoped></style>
